//
//  CollectV.swift
//  AliBaiChuan
//
//  Created by 郑东喜 on 2017/2/23.
//  Copyright © 2017年 郑东喜. All rights reserved.
//  单独添加uicollectionView

import UIKit

class CollectV: UIViewController {
    
    lazy var dataSource: NSMutableArray = {
        let a : NSMutableArray = ["1","2","3","4","5","6","7","8","9","10"]
        return a
    }()
    
    fileprivate let height : CGFloat = 50
    
    fileprivate lazy var horizontaoScrol: UIScrollView = {
        let vie : UIScrollView = UIScrollView.init(frame: CGRect.init(x: 0, y: 64, width: SW, height: self.height))
        vie.backgroundColor = UIColor.gray
        
        vie.alwaysBounceHorizontal = true
        vie.alwaysBounceVertical = false
        
        vie.showsHorizontalScrollIndicator = false
        return vie
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        
        // Do any additional setup after loading the view.
        
        //防止uiscrollview自动调整
        self.automaticallyAdjustsScrollViewInsets = false
        
        
        self.setUI()
    }
}

extension CollectV {
    fileprivate func setUI() -> Void {
        
        view.addSubview(horizontaoScrol)
        for i : Int in 0..<dataSource.count {
            let rect : CGRect = CGRect.init(x: CGFloat(i) * 60, y:0, width: 60, height: height)
            let bttt : UIButton = UIButton.init(frame: rect)
            bttt.backgroundColor = UIColor.randomColor()
            self.horizontaoScrol.addSubview(bttt)
            
            bttt.setTitle(dataSource[i] as? String, for: .normal)
            
        }
        
        self.horizontaoScrol.contentSize = CGSize.init(width: self.dataSource.count * 60, height: 0)
    }
    
}
